#!/usr/bin/env python
##
#                  ,           /)   
#   _   _ __  _/_   __    _  _(/  _ 
#  (___(/_/ (_(___(_/_)__(/_(_(__(/_
#                .-/                
#               (_/     
#
#  http://code.google.com/p/centipede/
#  Understanding & simplicity
#  Copyright 2009, Asbjorn Enge. All rights reserved.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
#  MA  02111-1307  USA
#
#  (C) 2010
#
##
#
#  Startup script
#
##
import os, sys

conf = {
    'address':'0.0.0.0',
    'port':8080,
}

options = []

def sh(command):
    print os.system(command)

def option(func):
    options.append(func.__name__)
    return func

@option
def install():
    sh("easy_install pip")
    sh("pip install -r requirements.txt")
    
@option
def setup():
    print "Add some setup stuff"

@option
def start():
    from wsgiref.simple_server import make_server
    import controllers
    http = make_server(conf['address'], conf['port'], controllers.make_app())
    print "Serving http://%s:%s" % ( conf['address'], conf['port'] )
    http.serve_forever()

if __name__ == '__main__':
    if len(sys.argv) > 1:
        try:
            getattr(sys.modules[__name__], sys.argv[1])()
        except (AttributeError,TypeError):
            print "* No option '%s'\n" % sys.argv[1]
            print "Usage: run [OPTION]"
            for option in options:
                print "  %s" % option
            
    else:
        start()

